package com.unusap.remote.core.remote.factory;

import org.apache.commons.lang.StringUtils;

/**
 * 提供webservice帮助方法
 * Created by IntelliJ IDEA.
 * User: danson
 * Date: 2009-8-20
 * Time: 16:09:34
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractWebServiceFactory {

    private static final String DEFAULT_SERVICE_SYMBOL = "remoting";

    private static final String SLASH = "/";

    private String serviceHost;

    private String serviceSymbol = DEFAULT_SERVICE_SYMBOL;

    public AbstractWebServiceFactory(String serviceHost) {
        this.serviceHost = StringUtils.removeEnd(serviceHost, SLASH);
    }

    public abstract <T> T getService(Class<T> serviceInterface, String serviceName);

    protected String constructServiceUrl(String serviceName) {
        return new StringBuilder(serviceHost)
                .append(SLASH)
                .append(removeSlash(serviceSymbol))
                .append(SLASH)
                .append(serviceName)
                .toString();
    }

    private String removeSlash(String string) {
        return StringUtils.remove(string, SLASH);
    }

}
